package com.gxa.service.impl;

import com.gxa.common.R;
import com.gxa.mapper.XxxTypeMapper;
import com.gxa.pojo.XxxType;
import com.gxa.service.XxxTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 周林森
 * Date: 2021/12/07 11:21:46
 * Description: 辅助资料列  类别业务
 * Version: V1.0
 */
@Service
public class XxxTypeServiceImpl implements XxxTypeService {

    @Autowired(required = false)
    private XxxTypeMapper xxxTypeMapper;
    //
    private XxxType getXxxType(Map map){
        XxxType xxxType = new XxxType();
        Object tableId1 = map.get("tableId");
        Object id1 = map.get("id");
        Object value1 = map.get("value");
        if(tableId1 == null){
            return new XxxType();
        }
        Integer tableId = Integer.parseInt((String)tableId1 );
        xxxType.setTableId(tableId);
        Integer id = 0;
        if(id1 != null){
            id = (Integer) id1;
        }
        xxxType.setId(id);
        String value = "";
        if(value1 != null){
            value = (String) map.get("value");
        }
        xxxType.setValue(value);
        return xxxType;
    }

    /**
     * 删除某类别
     * @param map
     * @return
     */
    @Override
    public R delXxxType(Map map) {
        XxxType xxxType = getXxxType(map);
        int i = xxxTypeMapper.delXxxType(xxxType);
        if(i>0){
            return new R(200,"删除成功");
        }
        return new R(200,"删除失败");
    }

    /**
     * 添加某类别
     * @param map
     * @return
     */
    @Override
    public R addXxxType(Map map) {
        XxxType xxxType = getXxxType(map);
        int i = xxxTypeMapper.addXxxType(xxxType);
        if(i>0){
            return new R(200,"添加成功");
        }
        return new R(200,"添加失败");
    }

    /**
     * 修改某类别
     * @param map
     * @return
     */
    @Override
    public R updateXxxType(Map map) {
        XxxType xxxType = getXxxType(map);
        int i = xxxTypeMapper.updateXxxType(xxxType);
        if(i>0){
            return new R(200,"修改成功");
        }
        return new R(200,"修改失败");
    }

    /**
     * 查询
     * @param map
     * @return
     */
    @Override
    public R queryXxxType(Map map) {
        List<Map> mapList = xxxTypeMapper.queryXxxTypeList(getXxxType(map));
        return new R(200,"查询成功",mapList);
    }

    //添加商品类别
    @Override
    public R addGoodsType(Object goods_type_name, Object parent_id) {
        xxxTypeMapper.addGoodsType(goods_type_name,parent_id);
        return new R(200,"添加成功");
    }

    @Override
    public R updateGoodsType(Map map) {
        xxxTypeMapper.updateGoodsType(map);
        return new R(200,"修改成功");
    }


}
